package com.gh.strategy.impl;

import com.gh.anno.Strategy;
import com.gh.exception.FruitException;
import com.gh.strategy.ProductStrategy;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @author heyu
 * @date 2022:11:06 10:00
 * NoFruitDiscount 不打折
 */
@Strategy("NoFruitDiscount")
@Component
public class ProductStrategyNoFruitDiscount implements ProductStrategy {
    @Override
    public BigDecimal calProductPrice(double price, Integer num , double discount) {
        BigDecimal  bigDecimal = (num >= 0&&discount>=0&&discount<=10&&price>=0)?BigDecimal.valueOf(price * num):null;

        if (bigDecimal==null) {
            throw new FruitException("参数有问题，请重新输入");
        }else {
            return bigDecimal;
        }
    }
}
